package org.opu.gui.component;

import java.awt.Component;
import java.awt.Dimension;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JSplitPane;

/**
 *
 * @author yuriy
 */
public class MainSplitPanel extends JSplitPane {
    private JComponent main;
    private MyJTabbedPane tabbedPane;

    public MainSplitPanel(JComponent main, Status status) {
        super(JSplitPane.VERTICAL_SPLIT);
        this.main = main;
        this.tabbedPane = new MyJTabbedPane(status);
        tabbedPane.setPreferredSize(new Dimension(400, 100));
        tabbedPane.setMinimumSize(new Dimension(100, 50));
        setLeftComponent(this.main);
        setRightComponent(this.tabbedPane);
        setDividerSize(2);
    }

    /**
     * Adds a component represented by a title and no icon to tabbet pane
     * (below main panel). Cover method for insertTab.
     * @param title the title to be displayed in this tab
     * @param icon the icon to be displayed in this tab
     * @param component the component to be displayed when this tab is clicked
     */
    public Component addTab(String title, Icon icon, Component component) {
        tabbedPane.addTab(title, icon, component);
        //tabbedPane.reinitLast();
        tabbedPane.reinitAll();
        return tabbedPane.getTabComponentAt(tabbedPane.getTabCount() - 1);
    }

    /**
     *  Removes the tab and component which corresponds to
     * first tab index with a given title
     * @param title the title for the tab
     */
    public Component remove(String title) {
        int index = tabbedPane.indexOfTab(title);
        Component ret = null;
        if (index >= 0) {
            ret = tabbedPane.getTabComponentAt(index);
            tabbedPane.remove(index);
        }
        return ret;
    }

    /**
     *  Return true if tabpane have now tabs
     * @return true if tabpane have now tabs
     */
    public boolean isNowTabs() {
        return tabbedPane.isNowTabls();
    }

    /**
     *  Reinit tab component to all tabs
     */
    public void reinitAll() {
        tabbedPane.reinitAll();
    }


}
